package com.hspedu.outputStream;

import java.io.*;

/**
 * @author LiuJinTao
 * @className BufferCopyInputOutput
 * @date 2024/06/28 0:26
 * @description TODO
 */
public class BufferCopyInputOutput {
    public static void main(String[] args) throws IOException {
        String srcpath = "e:\\壁纸1.jpg";
        String destpath = "e:\\壁纸2.jpg";
        BufferedInputStream bufferedInputStream = null;
        BufferedOutputStream bufferedOutputStream = null;
        bufferedInputStream = new BufferedInputStream(new FileInputStream(srcpath));
        bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(destpath, true));
        // 循环读取文件
        byte[] bytes = new byte[1024];
        int len = 0;
        while ((len = bufferedInputStream.read(bytes)) != -1) {
            bufferedOutputStream.write(bytes, 0, len);
        }

        if (bufferedOutputStream != null) bufferedOutputStream.close();
        if (bufferedInputStream != null) bufferedInputStream.close();
    }
}
